<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Full Layout - jQuery EasyUI Demo</title>
	<#include "./../common/header.html"/>
</head>
<body class="easyui-layout">
	<table id="dg" class="easyui-datagrid" title="" style="width:100%;height:64%"
		data-options="
				iconCls: 'icon-ok',
				singleSelect: true,
				url:'${ctx}/schedule/loadTask',
				toolbar: '#tb',
				pageSize:10,
				pagination:true,
				pageNumber:1,
			">
		<thead>
			<tr>
				<th data-options="field:'baseTaskType',width:80">任务名称</th>
				<th data-options="field:'dealBeanName',width:100">任务处理Bean</th>
				<th data-options="field:'heartBeatRate',width:60">心跳频率(毫秒)</th>
				<th data-options="field:'judgeDeadInterval',width:50">死亡间隔(毫秒)</th>
				<th data-options="field:'threadNumber',width:60">线程数</th>
				<th data-options="field:'fetchDataNumber',width:60">每次获取数据量</th>
				<th data-options="field:'executeNumber',width:60">每次执行数量</th>
				<th data-options="field:'sleepTimeNoData',width:110">没有数据休眠时长(毫秒)</th>
				<th data-options="field:'processorType',width:50">处理模式</th>
				<th data-options="field:'sleepTimeIntervalStr',width:130">处理完休眠时间(毫秒)</th>
				<th data-options="field:'expireOwnSignInterval',width:50">清除处理域信息时长(小时)</th>
				<th data-options="field:'permitRunStartTime',width:100">执行开始时间</th>
				<th data-options="field:'permitRunEndTime',width:100">执行结束时间</th>
				<th data-options="field:'maxTaskItemsOfOneThreadGroup',width:100,height:500">单线程组最大任务项</th>
				<th data-options="field:'taskParameter',width:100,height:500">自定义参数</th>
				<th data-options="field:'taskItems',width:100,height:500">任务项</th>
				
				
			</tr>
		</thead>
	</table>

  <table id="dg2" class="easyui-datagrid" title="" style="width:100%;height:18%"
		data-options="
				iconCls: 'icon-ok',
				singleSelect: true,
				url:'',
			">
		<thead>
			<tr>
			    <th data-options="field:'uuid',width:120">线程组编号</th>
				<th data-options="field:'ownSign',width:50">域</th>
				<th data-options="field:'ip',width:70">IP地址</th>
				<th data-options="field:'hostName',width:60">主机名称</th>
				<th data-options="field:'threadNum',width:50">线程数</th>
				<th data-options="field:'registerTime',width:70">注册时间</th>
				<th data-options="field:'heartBeatTime',width:70">心跳时间</th>
				<th data-options="field:'lastFetchDataTime',width:60">取数时间</th>
				<th data-options="field:'version',width:50">版本</th>
				<th data-options="field:'nextRunStartTime',width:130">下次开始</th>
				<th data-options="field:'nextRunEndTime',width:130">下次结束</th>
				<th data-options="field:'managerFactoryUUID',width:100">处理机器</th>
				<th data-options="field:'dealInfoDesc',width:100">处理详情</th>
			</tr>
		</thead>
	</table>
	
	
	 <table id="dg3" class="easyui-datagrid" title="" style="width:100%;height:18%"
		data-options="
				iconCls: 'icon-ok',
				singleSelect: true,
				url:'',
			">
		<thead>
			<tr>
				<th data-options="field:'taskItem',width:60">任务项</th>
				<th data-options="field:'currentScheduleServer',width:120">当前线程组</th>
				<th data-options="field:'requestScheduleServer',width:120">请求线程组</th>
				<th data-options="field:'sts',width:70">任务状态</th>
				<th data-options="field:'dealParameter',width:70">任务参数</th>
				<th data-options="field:'dealDesc',width:100">处理描述</th>
			</tr>
		</thead>
	</table>
	<div id="tb" style="height:auto">
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="add_taskType()">创建新任务</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="check_taskType()">查看任务</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="update_taskType()">修改任务</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear',plain:true" onclick="clear_taskType()">清理任务</a>
	    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" onclick="delete_taskType()">删除任务</a>
	    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="check_taskTypeRunInfo()">查看任务运行期信息</a>
	</div>

	<div id="add_dlg" class="easyui-dialog" closed="true" data-options="width:700,height:550">
		<div id="content">
		
		<form id="taskTypeForm" method="post" name="taskTypeForm" >
<table>
<tr>
	<td>任务名称:</td>
	<td><input type="text"  data-options="required:true"  class="easyui-textbox" id="baseTaskType" name="baseTaskType"   value="" width="30"/></td>
	<td></td>
</tr>
<tr>
	<td>任务处理的SpringBean:</td>
	<td><input type="text"  data-options="required:true"  class="easyui-textbox"  id="dealBeanName" name="dealBeanName"   value="" width="30"></td>
	<td></td>
</tr>
<tr>
	<td>心跳频率(毫秒):</td>
	<td><input type="text" data-options="required:true" class="easyui-numberbox" data-options="min:0,precision:0" id="heartBeatRate" name="heartBeatRate"  value="5000" width="30"></td>
	<td></td>
</tr>
<tr>
	<td>死亡间隔(毫秒):</td>
	<td><input type="text" data-options="required:true" class="easyui-numberbox" data-options="min:0,precision:0" id="judgeDeadInterval" name="judgeDeadInterval"   value="60000" width="30"></td>
	<td></td>
</tr>

<tr>
	<td>线程数:</td>
	<td><input type="text" data-options="required:true" class="easyui-numberbox" data-options="min:0,precision:0"  name="threadNumber" value="5" width="30"></td>
	<td></td>
</tr>
<tr>
	<td>每次获取数据量：</td>
	<td><input type="text" data-options="required:true" class="easyui-numberbox" data-options="min:0,precision:0"  name="fetchDataNumber" value="500"  width="30"></td>
	<td></td>
</tr>
<tr>
	<td>每次执行数量：</td>
	<td><input type="text" data-options="required:true" class="easyui-numberbox" data-options="min:0,precision:0"  name="executeNumber" value="1"  width="30"></td>
	<td>只在bean实现IScheduleTaskDealMulti才生效</td>
</tr>
<tr>
	<td>没有数据休眠时长(毫秒):</td>
	<td><input type="text" data-options="required:true" class="easyui-numberbox" data-options="min:0,precision:0"  name="sleepTimeNoData"   value="500" width="30"></td>
	<td></td>
</tr>

<tr>
	<td>处理模式:</td>
	<td><select id="processorType"  name="processorType"   >
            <option value="SLEEP" selected>SLEEP</option>
            <option value="NOTSLEEP">NOTSLEEP</option>
        </select>
	</td>
	<td></td>
</tr>
<tr>
	<td>每次处理完后休眠时间(毫秒):</td>
	<td><input type="text"  data-options="required:true" class="easyui-numberbox" data-options="min:0,precision:0"  name="sleepTimeInterval"  value="0" width="30"></td>
	<td></td>
</tr>
<tr>
	<td>清除处理域信息时长(小时):</td>
	<td><input type="text" data-options="required:true" class="easyui-numberbox" data-options="min:0,precision:0"  name="expireOwnSignInterval"  value="0" width="30"></td>
	<td></td>
</tr>
<tr>
	<td>执行开始时间:</td>
	<td><input type="text"    class="easyui-textbox"  name="permitRunStartTime"  value="" width="30"/></td>
	<td></td>
</tr>
<tr>
	<td>执行结束时间:</td>
	<td><input type="text"    class="easyui-textbox"  name="permitRunEndTime"  value="" width="30"/></td>
	<td></td>
</tr>
<tr>
	<td>单线程最大任务项:</td>
	<td><input type="text" data-options="required:true" class="easyui-numberbox" data-options="min:0,precision:0"  name="maxTaskItemsOfOneThreadGroup"  value="0" width="30"></td>
	<td>每一组线程能分配的最大任务数量，避免在随着机器的减少把正常的服务器压死，0或者空表示不限制</td>
</tr>
<tr>
	<td>自定义参数:</td>
	<td><input type="text"   class="easyui-textbox"   name="taskParameter"   value="" width="30"></td>
	<td></td>
</tr>
<tr>
	<td>任务项:</td>
	<td><input type="text"  class="easyui-textbox"   name="taskItems"   value="" width="30"></td>
	<td></td>
</tr>
</table>
</form>
		</div>
	</div>

</body>
<script>
$('#search').searchbox({
    searcher:function(value,name){
        //alert(value + "," + name)
        var sdate = $("#sdate").datebox('getValue');
        if(name=='all'){
        	$('#dg').datagrid('load',{udid:"",method:"",ip:"",queryDate:sdate});
        	return;
        }
       
        if(value==""){
        	$.messager.alert({
				title : '提示',
				msg : "请输入查询内容"
			});
        	return;
        }
        
        if(name=="udid"){
        	$('#dg').datagrid('load',{
        		udid: value,queryDate:sdate
        	});
        }
        
        if(name=="lvsessionid"){
        	$('#dg').datagrid('load',{
        		lvsessionid: value,queryDate:sdate
        	});
        }
        
        if(name=="method"){
        	$('#dg').datagrid('load',{
        		method: value,queryDate:sdate
        	});
        }
        
        if(name=="ip"){
        	$('#dg').datagrid('load',{
        		ip: value,queryDate:sdate
        	});
        }
    	
    },
});

function view_details(){
	var row =  $("#dg").datagrid('getSelected');  
	if(row!=null){
		$('#add_dlg').dialog({
			title:'错误详细信息',
			closed: false,
		    cache: false,
			buttons:[{  
	            text:'关闭',  
	            handler:function(){ 
	              $('#add_dlg').dialog('close');
	            }  
	        }],  
	        onOpen:function(){  
	        	$("#content").html(row.exception);
	       	 	//$('#add_contentt_dlg_{$rbtId}').dialog('refresh', '__URL__/toAddInfoForm&rbtId={$rbtId}');   
	        }  
		});
	} else {
		$.messager.alert({
			title : '提示',
			msg : "请选择一行"
		});
	}
	
}


function add_taskType(){
    $("input").removeAttr("readonly","readonly");
    $("#baseTaskType").parent().next().text("必须填写，不能有中文和特殊字符(如$)");
    $("input[name='baseTaskType']").prev().removeAttr("readonly");
   
	$('#add_dlg').dialog({
		title:'添加任务管理',
		closed: false,
		cache: false,
		buttons:[{ 
			text:'提交', 
			iconCls:'icon-ok',
			handler:function(){
				$("#add_dlg").find('#taskTypeForm').form('submit',{
					onSubmit:function(){
					 $("#taskTypeForm").attr('action', '${ctx}/schedule/createTasktype');
					var taskNameStr=$("#baseTaskType").val();
					if(taskNameStr.indexOf('$')>=0){
					      $.messager.alert({
								title : '提示',
								msg : "任务名不能包含字符$"
							});
							return false;
					}
				   var reg = /.*[\u4e00-\u9fa5]+.*$/; 
	               if(reg.test(taskNameStr)){
	                  $.messager.alert({
								title : '提示',
								msg : "任务名不能包含中文"
							});
							return false;
	               }
	             if(taskNameStr==null||taskNameStr==''||isContainSpace(taskNameStr)){
		                  $.messager.alert({
								title : '提示',
								msg : "任务名不能为空或包含空格"
							});
							return false;
	                }
					var flag = $(this).form('validate');
						return flag;
					},
					dataType:"json",
					success : function(response) {
						if(response=='true'){
							$.messager.alert({
								title : '提示',
								msg : "添加成功"
							});
						} else {
							$.messager.alert({
								title : '提示',
								msg : "该任务已存在，请先删除后再重新创建"
							});
						}
					
						$('#add_dlg').dialog('close');
						$('#dg').datagrid('reload'); 
					}
					
				});
				
			} 
		},{ 
			text:'关闭', 
			handler:function(){ 
				$('#add_dlg').dialog('close');
			} 
		}], 
		onOpen:function(){ 
			//$('#add_contentt_dlg_{$rbtId}').dialog('refresh', '__URL__/toAddInfoForm&rbtId={$rbtId}'); 
		} 
	});			
}

function check_taskType(){
    $("input").attr("readonly","readonly");
    var row = $("#dg").datagrid('getSelected');
	if(row!=null){
	$('#taskTypeForm').form('load',row);
	$('#add_dlg').dialog({
		title:'查看任务详情',
		closed: false,
		cache: false,
		buttons:[{ 
				text:'关闭', 
				handler:function(){ 
				 $("input").removeAttr("readonly","readonly");
					$('#add_dlg').dialog('close');
				} 
			}] 
		});
	} else {
		$.messager.alert({
			title : '提示',
			msg : "请选择一行"
		});
	}
}


function update_taskType(){
    $("input").removeAttr("readonly","readonly");
	var row = $("#dg").datagrid('getSelected');
	if(row!=null){
	$("#baseTaskType").parent().next().text("任务名称,不可更改");
	
	$("input[name='baseTaskType']").prev().attr("readonly","true");
	$('#taskTypeForm').form('load',row);
	$('#add_dlg').dialog({
		title:'修改任务管理',
		closed: false,
		cache: false,
		buttons:[{ 
			text:'提交', 
			iconCls:'icon-ok',
			handler:function(){
				$("#add_dlg").find('#taskTypeForm').form('submit',{
					onSubmit:function(){
					$("#taskTypeForm").attr('action', '${ctx}/schedule/updateTasktype');
					var flag = $(this).form('validate');
						return flag;
					},
					dataType:"json",
					success : function(response) {
						if(response=='true'){
							$.messager.alert({
								title : '提示',
								msg : "修改成功"
							});
						}else {
							$.messager.alert({
								title : '提示',
								msg : "修改失败"
							});
						}
					
						$('#add_dlg').dialog('close');
						$('#dg').datagrid('reload'); 
					}
					
				});
				
			} 
		},{ 
			text:'关闭', 
			handler:function(){ 
				$('#add_dlg').dialog('close');
			} 
		}], 
		onOpen:function(){ 
			//$('#add_contentt_dlg_{$rbtId}').dialog('refresh', '__URL__/toAddInfoForm&rbtId={$rbtId}'); 
		} 
	});			
	
	} else {
		$.messager.alert({
			title : '提示',
			msg : "请选择一行"
		});
	}
}

function delete_taskType(){
	var row = $("#dg").datagrid('getSelected'); 
	if(row!=null){
	var  baseTaskTypeName=row.baseTaskType;
		$.messager.confirm('删除?', '确认删除?', function(r){
			if(r){
				$.ajax({ url: "${ctx}/schedule/deleteTasktype?baseTaskType="+baseTaskTypeName, success: function(response){
					var data= $.parseJSON(response); 
					if(response=='true'){
						$("#dg").datagrid('reload');
					    $.messager.alert({
						title : '提示',
						msg : baseTaskTypeName+",删除成功"
					});
					}
					else {
					    $.messager.alert({
						title : '提示',
						msg : baseTaskTypeName+",删除失败"
					});
					}
				}});
			}

		});
	
	} else {
		$.messager.alert({
			title : '提示',
			msg : "请选择一行"
		});
	}
}

function clear_taskType(){
	var row = $("#dg").datagrid('getSelected');
	if(row!=null){
	var  baseTaskTypeName=row.baseTaskType;
				$.ajax({ url: "${ctx}/schedule/clearTasktype?baseTaskType="+baseTaskTypeName, success: function(response){
					var data= $.parseJSON(response); 
					if(response=='true'){
						$("#dg").datagrid('reload');
					    $.messager.alert({
						title : '提示',
						msg : baseTaskTypeName +",清理成功"
					});
					}else{
					    $.messager.alert({
						title : '提示',
						msg : baseTaskTypeName +",清理失败"
					});
					}
					
				}});
	
	} else {
		$.messager.alert({
			title : '提示',
			msg : "请选择一行"
		});
	}
}

function isContainSpace(array) {   
	if(array.indexOf(' ')>=0){
		return true;
	}
    return false;
}

function check_taskTypeRunInfo(){
    var row = $("#dg").datagrid('getSelected');
	if(row!=null){
	var baseTaskTypeName=row.baseTaskType;
	var urlStr = "${ctx}/schedule/loadServerListInfo?baseTaskType=" + baseTaskTypeName;
            $('#dg2').datagrid('options').url = urlStr;
            $('#dg2').datagrid('reload'); 
            
    var urlStr2 = "${ctx}/schedule/loadTaskItemListInfo?baseTaskType=" + baseTaskTypeName;
            $('#dg3').datagrid('options').url = urlStr2;
            $('#dg3').datagrid('reload'); 
                  
	} else {
		$.messager.alert({
			title : '提示',
			msg : "请选择一行"
		});
	}
}

</script>
</html>